#!/bin/bash
#设置日志文件存放目录
Logs_path="/data/Application/nginx/logs"
#设置pid文件
Pid_path="/data/Application/nginx/nginx.pid"
#设置日志产生的月份
Month=`date +%Y-%m`
#设置日期
Date=`date +%Y-%m-%d`
#设置分割时间点
Time=`date +%H`
WaitTime=$((24*60*60))

LogCut()
{
    	cd $Logs_path
    	if [ -e $Month ]
	then
    	    echo "Director exists!"
    	else
    	    echo "Director not exists!"
    	    mkdir $Month  
	    if [ $Time == "16" ]
   	    then
	    	echo "copy access.log to new directory!"
	    	cp $Logs_path/access.log $Logs_path/$Month/access_$Date.log
	    	kill -USR1 `cat ${Pid_path}`
    	    fi
	fi
	sleep $WaitTime
	return 0
}

case $1 in
start)
	LogCut &
	;;
stop)
	kill -9 `ps aux | grep LogCut | grep -v grep | awk '{print $2}'`>/dev/null 
	;;
*)
	echo "Usage ERROR!Please use start or stop!"
esac
